package ta.dao;
import java.util.ArrayList;
import java.util.List;

import ta.pojo.Category;
import ta.utils.JDBCUtils;
import ta.utils.PageInfo;
public class CategoryDao{
	//add
	public boolean add(Category category)
	{
		String sql="insert into category(cid,cname) values(?,?)";
		Object[] params={category.getCid(),category.getCname()};
		return JDBCUtils.update(sql, params);
	}
	//del	
	public boolean del(String cid)
	{			
		String sql="delete from category where cid=?";
		Object[] params= {cid};
		return JDBCUtils.update(sql, params);
	}
	//getById
	public Category getById(String cid)
	{			
		String sql="select * from category where cid=?";		
		Object[] params= {cid};
		return JDBCUtils.getBean(sql,params,Category.class);
	}
	//modify
	public boolean edit(Category category)
	{
		StringBuilder str=new StringBuilder("update blog set ");
		List<Object> list=new ArrayList<Object>();
		if(category.getCname()!=null)
		{
			str.append("cname=?,");
			list.add(category.getCname());
		}
		str.deleteCharAt(str.length()-1);			
		str.append(" where cid=?");			
		list.add(category.getCid());
		Object[] params= list.toArray();
		return JDBCUtils.update(str.toString(), params);
	}
	//getAll
	public List<Category> getAll()
	{	  	
		String sql = "select * from category ";	
		List<Category> list = JDBCUtils.getList(sql,  Category.class);
		return list;  
	}
	
}
	